import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
import * as path from 'path';
import { UserModule } from './user/user.module';
import { JwtAuthGuard } from './user/auth/jwtAuthGuard';
import { CustomReponseInterceptor } from './shared/interceptor/response.interceptor';
import { CustomExceptionFilter } from './shared/exceptionFilter/customExceptionFilter';
import { TokenStateInterceptor } from './shared/interceptor/token.interceptor';
import { RedisService } from './shared/redis.service';
import { ChatModule } from './chat/chat.module';
import { SysDictModule } from './sys_dict/sys_dict.module';

@Module({
  imports: [
    // mysql配置(需要手动切换环境)
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: '127.0.0.1',
      // host: '59.110.222.95', //阿里云
      port: 3306,
      username: 'yang',
      password: '123456',
      database: 'my_database',
      synchronize: true,
      entities: [path.join(__dirname, './**/entities/*{.js,.ts}')],
    }),
    UserModule,
    ChatModule,
    SysDictModule,
  ],
  controllers: [],
  providers: [
    // 全局配置auth Grand
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard,
    },
    // 全局配置interceptor
    {
      provide: APP_INTERCEPTOR,
      useClass: TokenStateInterceptor,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: CustomReponseInterceptor,
    },
    // 全局异常 filter
    {
      provide: APP_FILTER,
      useClass: CustomExceptionFilter,
    },
    RedisService,
  ],
})
export class AppModule {}
